<?php
/**
 * Klasse zur Objektauflistung
 * Ausgabe erfolgt als Tabelle
 *
 * @author		Joachim Ruf
 * @copyright	Copyright (c) 2003-2010 Loresoft Software (http://www.loresoft.de)
 * @license		http://yapary.loresoft.de/lizenzbedingungen     New BSD License
 *
 * */


Class Yapary_Listing_Object_ViewerTable Implements Yapary_Listing_Object_IViewer
{
    const NEWLINE = "\n";

    private $borderName  = 'objectListingTable';
    private $descName    = 'objectListingTableDesc';
    private $itemName    = 'objectListingTableRow';
    private $descValue   = 'objectListingTableCol';


    function __construct ()
    {

    }


    /**
     * @param array[] $arrData	:	Feld mit enthaltenen Datensaetzen
     * @return string
     * */
    public function display (array $arrData)
    {
        $rows      = 0;
        $result    = '';

        if (count($arrData) == 0) {
            trigger_error('missing data', E_USER_ERROR);
            return '';
        }

        // Ueberschrift
        $resultTmp = '';
        foreach ($arrData[0] as $desc => $val) {
            $resultTmp .= '<th class="'.$this->descName.' '.$this->descName.(++$rows).'">'.$desc.'</th>';
        }
        $result = '<tr>'.$resultTmp.'</tr>'.self::NEWLINE;


        // Datensaetze
        foreach ($arrData as $i => $line) {
            $resultTmp = '';
            $k         = 0;

            foreach ($line as $key => $val) {
                $resultTmp .= '<td class="'.$this->descValue.' '.$this->descValue.(++$k).'">'.$val.'</td>';
            }

            $result .= '<tr class="'.$this->itemName.' '.$this->itemName.($i).'">'.$resultTmp.'</tr>'.self::NEWLINE;
        }

        return '<table class="'.$this->borderName.'" border="0" width="100%">
        		'.$result.'
        		</table>';
    }


}


?>